//
//  HMEmoticonCollectionView.swift
//  WeiBo14
//
//  Created by HM on 16/3/12.
//  Copyright © 2016年 HM. All rights reserved.
//

import UIKit

class HMEmoticonCollectionView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: layout)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI(){
        // 设置cell条目的大小
        backgroundColor = UIColor.clearColor()
        // 隐藏滚动条
        self.showsHorizontalScrollIndicator = false
        self.pagingEnabled = true
        self.bounces = false
        
       

    }
    
    override func layoutSubviews() {
        // 1. 取layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        // 2. 设置条目大小
        layout.itemSize = self.frame.size
        // 3. 间距
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        // 4. 设置滚动方向
        layout.scrollDirection = .Horizontal
        
        // 调用layoutSubview的之后,会去走数据源方法,而这个时候我们已经把itemSize设置好了,而现在一个界面只显示个cell,所以就不会出现一起加载10个cell的情况
        super.layoutSubviews()
        
    }
}
